const propsMixin = {
	data() {
		return {
			show: false,
			loading: false
		}
	},
	props: {
		record: {
			type: Object,
			default: function () {
				return {}
			}
		},
		title: {
			type: String,
			default: "未定义"
		},
		option: {
			type: String,
			default: "create"
		},
		namespace: {
			type: String,
			default:null
    },
    type:{
      type:String,
      default:'ghost'
    },
    size: {
      type: String,
      default: 'default'
    },
    icon: String,
    perm: {
      type: String,
      default: ''
    },
	},
	computed: {
		dispatch() {
			return this.$store ? this.$store.dispatch : this.$parent.$data.self.$store.dispatch
		},
		row() {
			const row = this.record
			delete row.mtime
			delete row.ctime
			delete row.createId
			delete row.available
			delete row.salt
			return row
		},
		content() {
			return this.option === 'create' ? '确定保存吗？' : '确定更新吗？'
		},
		requestUrl() {
			return this.option === 'create' ? `${this.namespace}/save` : `${this.namespace}/update`
		},
		reloadUrl() {
			return `${this.namespace}/fetch`
		}
	},
	methods: {
		ok() {
			this.$Modal.confirm({
				title: '操作提示',
				content: this.content,
				onOk: () => {
          this.loading = true
          console.log({ ...this.formItem, id: this.formItem.id })
					this.dispatch(this.requestUrl, { ...this.formItem, id: this.formItem.id }).then((response) => {
						if (response) {
							const { httpCode, msg } = response
							if (httpCode == 200) {
								this.show = false;
								this.dispatch(this.reloadUrl)
							} else {
								this.$Message.error(msg || '操作失败')
							}
						}
						this.loading = false
					})
				},
				onCancel: () => {
					this.loading = false
				}
			});
		},
		onSubmit(param) {
			this.$Modal.confirm({
				title: '操作提示',
				content: this.content,
				onOk: () => {
					this.loading = true
					this.dispatch(this.requestUrl, param).then((response) => {
						if (response) {
							const { httpCode, msg } = response
							if (httpCode == 200) {
								this.dispatch(this.reloadUrl)
							} else {
								this.$Message.error(msg || '操作失败')
							}
						}
						this.loading = false
					})
				},
				onCancel: () => {
					this.loading = false
				}
			});
		}
	}
}

export default propsMixin
